<template>
	<view>
		<!-- 顶部导航-->
		<view class="header-box">
			<image class="header-top-right" @click.stop="$helper.to('/pages/views/setting/setting')"
				src="/static/image/mine-set.png" mode=""></image>
			<view class="user-info-box">
				<view class=" flex justify-start">
					<view class="user-img" @click="$helper.to('/pages/views/userInfo/userInfo')">
						<image :src="userInfo.images ?  userInfo.images : '/static/image/user.png'" class="img" mode="">
						</image>
					</view>
					<view class="user-info" @tap="login()">
						<view class="user-name flex">
							<view class="">
								{{userInfo.user_nickname}}
							</view>
							<image style="width: 54rpx;height: 28rpx;margin-left: 10rpx;"
								@click="$helper.to('/pages/views/openVip/openVip')" v-if="userInfo.vip==true"
								src="/static/image/mine/vips.png" mode=""></image>
						</view>
						<view class="user-phone flex">
							<view class="">团伴ID:{{userInfo.id}}</view>
							<image style="width: 24rpx;height: 24rpx;margin-left: 20rpx;"
								src="/static/image/mine/copy.png" mode=""></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="order">
			<view class="order-box">
				<view class="order-list">
					<view class="list-item" @click="$helper.to('/pages/views/focusList/focusList')">
						<view class="badge">{{userInfo.gz}}</view>
						<view class="name">关注</view>
					</view>
					<view class="list-item" @click="$helper.to('/pages/views/fansList/fansList')">
						<view class="badge">{{userInfo.fs}}</view>
						<view class="name">粉丝</view>
					</view>
					<view class="list-item" @click="$helper.to('/pages/views/visitorList/visitorList')">
						<view class="badge">{{userInfo.fk}}</view>
						<view class="name">访客</view>
					</view>
					<view class="list-item" @click="$helper.to('/pages/views/footprintList/footprintList')">
						<view class="badge">{{userInfo.zj}}</view>
						<view class="name">足迹</view>
					</view>
				</view>
			</view>
			<view class="vip-box flex justify-between">
				<view class="flex">
					<image class="vip-box-1" src="/static/image/mine/vip-bg1.png" mode=""></image>
					<image class="vip-box-2" src="/static/image/mine/vip-bg2.png" mode=""></image>
				</view>
				<view class="vip-box-3" @click="$helper.to('/pages/views/openVip/openVip')">
					立即开通
				</view>
			</view>
			<view class="more-box">
				<view class="order-title flex justify-between">
					<view class="title-name">我的订单</view>
					<view class="title-right flex" @click="handleMyorder">
						<view class="">
							全部
						</view>
						<image src="/static/image/find/right.png" mode=""></image>
					</view>
				</view>
				<view class="lists">
					<view class="li" @click="navto(i)" v-for="(item,i) in lists">
						<image :src="item.img" mode=""></image>
						<view class="name">
							{{item.name}}
						</view>
						<view class="top-num">9</view>
					</view>
				</view>
			</view>
			<view class="more-box">
				<view class="order-title flex justify-between">
					<view class="title-name">我的接单</view>
					<view class="title-right flex">
						<view class="" @click="handleMyReceing">
							全部
						</view>
						<image src="/static/image/find/right.png" mode=""></image>
					</view>
				</view>
				<view class="lists">
					<view class="li" style="justify-content: space-around;" @click="navto(i)"
						v-for="(item,i) in lists4">
						<image :src="item.img" mode=""></image>
						<view class="name">
							{{item.name}}
						</view>
						<view class="top-num">9</view>
					</view>
				</view>
			</view>
			<view class="more-box">
				<view class="order-title">
					<view class="title-name">常用功能</view>
				</view>
				<view class="lists">
					<view class="li" @click="navto(item.name)" v-for="(item,i) in lists2">
						<image :src="item.img" mode=""></image>
						<view class="name">
							{{item.name}}
						</view>
					</view>
				</view>
			</view>
			<view class="more-box">
				<view class="order-title">
					<view class="title-name">其他功能</view>
				</view>
				<view class="lists">
					<view class="li" v-for="(item, i) in filteredLists3" @click="navto(item.name)">
						<view>
							<image :src="item.img" mode=""></image>
							<view class="name">{{item.name}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<image src="/static/image/Index/point-kefu.png" mode="" @click="handleMore" class="kefu"></image>
		<!-- 我的服务 -->

		<!-- 底部打电话-->
		<uni-popup class="select_popup" ref="popupMore" :mask-click="true" type="bottom">
			<view class="morePopup">
				<view class="selectBlack">139999999</view>
				<view class="selectDel">拨打电话</view>
				<view class="selectclose" @click="closeMore">取消</view>
			</view>
		</uni-popup>

		<!-- 弹出层 -->
		<uni-popup ref="refundWayPopup" :show="true" type="center" class="refundWay">
			<view class="call-pup">
				<view class="call-pup-title">
					提示
				</view>
				<view class="call-pup-content">
					是否拨打400-1234-1234？
				</view>
				<view class="btns flex">
					<view class="btn-left" @click="cancles">
						取消
					</view>
					<view class="btn-right" @click="callPhone">
						立即拨打
					</view>
				</view>
			</view>
		</uni-popup>

		<!-- 弹出层app分享 -->
		<uni-popup :mask-click="true" ref="popupAppShow" type="bottom">
			<view class="pyq-box">
				<view class="pyq-box-top">
					<view class=""></view>
					<view class="">— 分享到 —</view>
					<image @click="$refs.popupAppShow.close('bottom')" src="/static/image/activity/cancle.png" mode="">
					</image>
				</view>
				<view class="pyq-box-middle">
					<view class="pyq-box-content">
						<image src="/static/image/activity/wx.png" mode=""></image>
						<view class="">
							微信
						</view>
					</view>
					<view class="pyq-box-content">
						<image src="/static/image/activity/pyq.png" mode=""></image>
						<view class="">
							朋友圈
						</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				imgBaseUrl: this.$http.imgBaseUrl,
				token: '',
				userInfo: {},
				user: '',
				mobile: '',
				lists: [{
						img: '/static/image/mine/mine-1.png',
						name: '待付款'
					},
					{
						img: '/static/image/mine/mine-2.png',
						name: '待消费'
					},
					{
						img: '/static/image/mine/mine-3.png',
						name: '已完成'
					},
					{
						img: '/static/image/mine/mine-4.png',
						name: '退款/售后'
					}
				],
				lists4: [{
						img: '/static/image/mine/mine-2.png',
						name: '待核销'
					},
					{
						img: '/static/image/mine/mine-3.png',
						name: '已完成'
					},
					{
						img: '/static/image/mine/mine-4.png',
						name: '退款/售后'
					}
				],
				lists2: [{
					img: '/static/image/mine/mine-5.png',
					name: '我的钱包'
				}, {
					img: '/static/image/mine/mine-6.png',
					name: '我的积分'
				}, {
					img: '/static/image/mine/mine-7.png',
					name: '我的动态'
				}, {
					img: '/static/image/mine/mine-8.png',
					name: '我的空间'
				}],
				lists3: [{
						img: '/static/image/mine/mine-9.png',
						name: '我的相册'
					},
					{
						img: '/static/image/mine/mine-10.png',
						name: '达人管理'
					},
					{
						img: '/static/image/mine/mine-11.png',
						name: '代理中心'
					},
					{
						img: '/static/image/mine/mine-12.png',
						name: '商家认证'
					},
					{
						img: '/static/image/mine/mine-12.png',
						name: '商家发布'
					},
					{
						img: '/static/image/mine/mine-13.png',
						name: '语言互动'
					},
					{
						img: '/static/image/mine/mine-14.png',
						name: '去过地方'
					},
					{
						img: '/static/image/mine/mine-15.png',
						name: 'APP分享'
					},
					{
						img: '/static/image/mine/mine-16.png',
						name: '意见反馈'
					},
				],
				countList: ''
			};
		},
		onShow() {
			this.getUserInfos();
			this.orderCount(); //订单数量
		},
		computed: {
		  filteredLists3() {
		    return this.lists3.filter(item => {
		      // 如果不是商家认证或发布，直接显示
		      if (item.name !== '商家认证' && item.name !== '商家发布') {
		        return true;
		      }
		      // 如果是商家相关功能，检查用户店铺状态
		      return this.userInfo.store == 1; // 使用松散比较，兼容字符串和数字
		    });
		  }
		},
		methods: {
			//获取用户信息
			getUserInfos() {
				this.$http.getUserInfo().then(res => {
					if (res.code == '1') {
						this.userInfo = res.data;
						this.user = res.user
						this.mobile = res.data.mobile.replace(res.data.mobile.substring(3, 7), '****')
					}

					if (res.code == '-201') {
						this.$helper.to('/pages/views/login/login')
					}
				})
			},
			// 获取订单数量
			orderCount() {
				this.$http.getOrderList({
					status: '',
				}).then(res => {
					this.countList = res.data;
				})
			},
			handleMore() {
				this.$refs.popupMore.open()
			},
			closeMore() {
				this.$refs.popupMore.close()
			},
			// 关闭弹窗
			cancles() {
				this.$refs.refundWayPopup.close();
			},
			// 拨打电话
			callPhone() {
				this.$refs.refundWayPopup.close();
				uni.makePhoneCall({
					phoneNumber: '13569486320' //仅为示例
				});
			},
			//跳转我的订单
			handleMyorder() {
				this.$helper.to('/pages/views/myOrder/myOrder')
			},
			// 我的接单
			handleMyReceing() {
				this.$helper.to('/pages/views/receivingOrders/receivingOrders')
			},

			// 我的服务跳转
			navto(name) {
				if (name == '我的空间') return this.$helper.to('/pages/views/mySpace/mySpace')
				if (name == '我的钱包') return this.$helper.to('/pages/views/myWallet/myWallet')
				if (name == '我的积分') return this.$helper.to('/pages/tabBar/index/rechargePoint')
				if (name == '商家认证') {
					// return this.$helper.to('/pages/views/myJoinIn/myJoinIn')
				}
				if (name == '语言互动') return this.$helper.to('/pages/views/vioceInter/vioceInter')
				if (name == '我的相册') return this.$helper.to('/pages/views/photoAlbum/photoAlbum')
				if (name == '达人管理') return this.$helper.to('/pages/views/management/management')
				if (name == '代理中心') return this.$helper.to('/pages/views/agent/agent')
				if (name == '我的动态') return this.$helper.to('/pages/views/myUpdates/myUpdates')
				if (name == 'APP分享') {
					this.$refs.popupAppShow.open()
					return
				}
				if (name == '意见反馈') return this.$helper.to('/pages/views/Feedback/Feedback')
				// if (uni.getStorageSync('token')) {
				// 	if (index == 0) return this.$helper.to('/pagesE/myCollect/myCollect');
				// 	if (index == 1) return this.$helper.to('/pagesE/myAddress/myAddress');
				// 	if (index == 2) return this.$helper.to('/pagesE/feedBack/feedBack');
				// 	if (index == 3) this.$refs.refundWayPopup.open();
				// } else {
				// 	this.login()
				// }
			},
			clickOrder(index) {
				if (uni.getStorageSync('token')) {
					this.$helper.to('/pagesE/orderList/orderList?id=' + index)
					// uni.navigateTo({
					// 	url: '/pagesE/orderList/orderList?id='+index
					// })
				} else {
					this.login()
				}
			},
			// 授权
			login() {
				if (uni.getStorageSync('token')) {
					this.$helper.to('/pagesE/userInfo/userInfo')
				} else {
					let that = this
					var code = ''
					uni.login({
						provider: 'weixin',
						success: function(logRes) {
							code = logRes.code;
						}
					});
					// 获取code
					uni.getUserProfile({
						desc: "作为展示",
						success: res => {
							let param = {
								code: code,
								iv: res.iv,
								encryptedData: res.encryptedData,
								rawData: res.rawData,
								signature: res.signature
							}
							this.$http.userLogin(param).then(res => {
								uni.hideToast();
								uni.switchTab({
									url: '/pages/tabbar/tab-1/tab-1'
								})
								uni.setStorageSync('userId', res.userId)
								uni.setStorageSync('token', res.token)
							})
						},
						fail: (err) => {
							console.log("获取失败", err);
						}
					})
				}
			}
		}
	};
</script>

<style lang="scss">
	page {
		background-color: #F8F8F8;
	}

	.select_popup {
		z-index: 9999;
		width: 100%;

		// 客服弹框
		.morePopup {
			background-color: #fff;
			height: 398rpx;
			border-radius: 30rpx 30rpx 0 0;

			.selectBlack {
				margin: 0 30rpx;
				font-size: 30rpx;
				border-bottom: 1px solid #f8f8f8;
				height: 118rpx;
				text-align: center;
				line-height: 118rpx;
				color: #000;
			}

			.selectDel {
				font-size: 30rpx;
				height: 118rpx;
				text-align: center;
				line-height: 118rpx;
				font-weight: bold;
				color: #000;
			}

			.selectclose {
				font-size: 30rpx;
				border-top: 16px solid #f8f8f8;
				height: 118rpx;
				text-align: center;
				line-height: 118rpx;
				color: #999;
			}
		}

	}

	.header-box {
		width: 100%;
		height: 400rpx;
		background-image: url('/static/image/mine-bg.png');
		background-size: 100% 100%;
		background-repeat: no-repeat;
		position: relative;
		padding-top: calc(44px + var(--status-bar-height));

		.header-top-right {
			width: 36rpx;
			height: 36rpx;
			position: absolute;
			right: 50rpx;
		}

		// 用户信息
		.user-info-box {
			display: flex;
			margin-left: 50rpx;

			.icon-right {
				margin-top: 60rpx;
			}

			.user-img {
				padding: 0 30upx 0 20upx;

				.img {
					width: 120upx;
					height: 120upx;
					border-radius: 50%;
					background-color: #efefef;
				}
			}

			.user-info {
				.user-name {
					font-size: 36upx;
					font-weight: 500;
					color: #fff;
					line-height: 85rpx;
					align-items: center;
				}

				.user-phone {
					font-size: 24rpx;
					font-weight: 500;
					color: #FFFFFF;
					line-height: 10rpx;
					opacity: 0.5;
					align-items: center;
				}
			}
		}
	}

	.vip-box {
		width: 690rpx;
		height: 135rpx;
		margin: 20rpx auto;
		background-image: url('/static/image/mine/vip-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 100%;
		align-items: center;
		padding: 0 25rpx;

		.vip-box-1 {
			width: 56rpx;
			height: 56rpx;
		}

		.vip-box-2 {
			width: 270rpx;
			height: 56rpx;
			margin-left: 20rpx;
		}

		.vip-box-3 {
			width: 144rpx;
			height: 56rpx;
			align-items: center;
			background-image: url('/static/image/mine/vip-bg3.png');
			background-size: 100%;
			background-repeat: no-repeat;
			line-height: 56rpx;
			font-weight: 500;
			font-size: 24rpx;
			color: #150E33;
			text-align: center;
		}
	}

	// 订单模块
	.order {
		width: 100%;
		padding: 25rpx;
		border-radius: 30rpx;
		margin-top: -100rpx;
		background: #FFFFFF;
		position: absolute;
		padding-bottom: 86rpx;

		.order-box {
			width: 100%;
			height: 100%;

			.order-title {
				display: flex;
				justify-content: space-between;
				align-items: center;
				width: 100%;
				height: 82rpx;
				color: rgba(0, 0, 0, 0.8);
				background-color: #fff;
				border-top-left-radius: 15upx;
				border-top-right-radius: 15upx;

				.title-name {
					font-size: 32rpx;
					font-weight: 800;
					color: #333333;
				}

				.look-all-btn {
					display: flex;
					align-items: center;
					font-size: 24upx;
					color: rgba(0, 0, 0, 0.4);

					.jinru {
						margin-left: 12upx;
					}
				}
			}

			.order-list {
				margin-top: 30rpx;
				display: flex;
				justify-content: space-between;
				width: 100%;
				// height: 200rpx;
				background-color: #fff;
				padding: 0 24upx;
				border-bottom-left-radius: 15upx;
				border-bottom-right-radius: 15upx;

				.list-item {
					position: relative;
					width: 100%;
					text-align: center;

					.name {
						font-weight: 400;
						font-size: 24rpx;
						color: #333333;
						margin-top: 12upx;
					}

					.badge {
						font-weight: 500;
						font-size: 40rpx;
						color: #000000;
					}
				}
			}
		}
	}

	.order-title {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 100%;
		height: 82rpx;
		padding: 0 24rpx;
		color: rgba(0, 0, 0, 0.8);
		border-top-left-radius: 15upx;
		border-top-right-radius: 15upx;

		.title-name {
			font-size: 32rpx;
			font-weight: 500;
			color: #000;
		}

		.title-right {
			font-size: 26rpx;
			color: #999999;

			image {
				width: 10rpx;
				height: 18rpx;
				margin: 10rpx 0 0 18rpx;
			}
		}

		.look-all-btn {
			display: flex;
			align-items: center;
			font-size: 24upx;
			color: rgba(0, 0, 0, 0.4);

			text {
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 400;
				line-height: 33px;
				color: #999999;
			}

			.jinru {
				margin-left: 12upx;
			}
		}
	}

	.lists {
		display: flex;
		flex-wrap: wrap;
		// background-color: #fff;

		.li {
			margin-bottom: 40rpx;
			text-align: center;
			width: 25%;
			position: relative;
		}

		image {
			width: 48rpx;
			height: 48rpx;
			margin: 0 auto;

		}

		.top-num {
			position: absolute;
			top: -10rpx;
			right: 42rpx;
			background: red;
			color: #fff;
			font-size: 18rpx;
			border-radius: 50%;
			width: 30rpx;
			height: 30rpx;
		}

		.name {
			text-align: center;
			font-size: 28rpx;
			color: #333333;
		}
	}

	.my-service {
		width: 700rpx;
		margin: 0 auto;
		padding: 25rpx;
		background: #fff;
		border-radius: 15rpx;
		color: #000;

		.my-service-title {
			font-weight: 800;
			color: #333333;
			font-weight: blod;
			font-size: 32rpx;
			margin-bottom: 20rpx;
		}

		.service-item {
			margin-bottom: 20rpx;
			margin-right: 20rpx;

			image {
				width: 56rpx;
				height: 56rpx;
				margin: 0 auto;
				margin-bottom: 15rpx;
			}

			.service-item-text {
				color: #333333;
				font-size: 26rpx;
			}
		}
	}

	.call-pup {
		width: 600rpx;
		height: 292rpx;
		background: #FDFDFD;
		opacity: 1;
		border-radius: 16rpx;
		position: relative;

		.call-pup-title {
			font-size: 36rpx;
			font-weight: bold;
			line-height: 38rpx;
			color: #333333;
			text-align: center;
			margin-top: 30rpx;
		}

		.call-pup-content {
			text-align: center;
			font-size: 28rpx;
			font-weight: 500;
			color: #666666;
			margin-top: 50rpx;
		}

		.btns {
			position: absolute;
			width: 100%;
			bottom: 0;
			text-align: center;
			font-size: 32rpx;
			font-weight: 500;
			line-height: 90rpx;
			height: 100rpx;

			.btn-left {
				border: 1rpx solid #eee;
				width: 50%;
				color: #999999;
			}

			.btn-right {
				color: #3391FF;
				border: 1rpx solid #eee;
				width: 50%;
			}
		}
	}

	.pyq-box {
		width: 100%;
		height: 428rpx;
		background-color: #fff;
		border-radius: 20rpx 20rpx 0 0;
		padding: 20rpx;
		margin-bottom: 60rpx;

		.pyq-box-top {
			display: flex;
			justify-content: space-between;
			font-weight: 500;
			font-size: 36rpx;
			color: #000000;

			image {
				width: 36rpx;
				height: 36rpx;
			}
		}

		.pyq-box-middle {
			display: flex;
			justify-content: space-around;
			font-size: 28rpx;
			color: #666666;
			text-align: center;
			margin-top: 60rpx;

			image {
				width: 140rpx;
				height: 140rpx;
				margin-bottom: 20rpx;
			}
		}
	}

	.kefu {
		width: 80rpx;
		height: 80rpx;
		position: fixed;
		bottom: 190rpx;
		right: 30rpx;
		// border-radius: 50%;
		// border:1px solid rgba(0,0,0,0.3)
	}
</style>